package com.lkk.testcase;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.client.ClientProtocolException;
import org.hibernate.annotations.MetaValue;
import org.testng.Assert;
import org.testng.Reporter;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lkk.data.ExcelDataEntity;
import com.lkk.data.ExcelDataException;
import com.lkk.data.Log;
import com.lkk.interaction.RestfulClient;
import com.lkk.util.CommonUtil;
import com.lkk.util.Constant;
import com.lkk.util.EntityListUtil;
import com.lkk.util.Red_Excel;

public class apiTest1 extends CaseSuper{
	/**
	 * 指定需要用到的测试编号
	 */
	private String caseNum1 = "xxx-1";
	private String caseNum2 = "xxx-3";
	
	@BeforeClass
	public void startCaseClass() {
		Log.startTestCase();
	}

	@BeforeMethod
	public void startCaseMethod() {
		caseNumList.add(caseNum1);
		caseNumList.add(caseNum2);
	}
	@Test(priority =1)
	public void case1() {
		//获取请求实体对象
		getExcelDataEntity(caseNumList.get(0));
		//获取参数
		getParam();
		//发送请求
		getResponse(caseNum1);
		//获取断言属性
		String errorMsg = responseBody.getString("errorMsg");
		String errorCode = responseBody.getString("errorCode");
		//获取record参数的字符串
		String recordString = responseBody.getString("record");
		//转为jsonObject格式
		JSONObject recordObject = JSON.parseObject(recordString);
		//获取id赋值给公共参数userId
		CommonUtil.userId= recordObject.getString("id");
		//断言判断
		Assert.assertEquals(errorMsg, assertions.get("errorMsg"));
		Assert.assertEquals(errorCode, assertions.get("errorCode"));
		Assert.assertEquals(Integer.toString(responseCode),status);
	}
	@Test(priority =2)
	public void case1_1() {
		//获取请求实体对象
		getExcelDataEntity(caseNumList.get(1));
		//获取参数
		getParam();
		//发送请求
		getResponse(caseNum2);
		//获取断言属性
		String errorMsg = responseBody.getString("errorMsg");
		String errorCode = responseBody.getString("errorCode");
		//获取record参数的字符串
		String recordString = responseBody.getString("record");
		//转为jsonObject格式
		JSONObject recordObject = JSON.parseObject(recordString);
		//断言判断
		Assert.assertEquals(errorMsg, assertions.get("errorMsg"));
		Assert.assertEquals(errorCode, assertions.get("errorCode"));
		Assert.assertEquals(Integer.toString(responseCode),status);
	}

	@AfterMethod
	public void endCaseMethod() {
		Log.endTestCase();
	}
	
}
